package com.yb.xczx.cloud.gateway.config;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.yb.core.enums.HttpCode;
import com.yb.core.model.WhiteListProperties;
import com.yb.core.model.XczxResult;
import com.yb.core.web.annotation.EnableWhiteListConfig;
import com.yb.xczx.cloud.gateway.filter.GlobalAuthFilter;
import com.yb.xczx.cloud.gateway.filter.WrapperResponseGlobalFilter;
import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.filter.NettyWriteResponseFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import reactor.core.publisher.MonoSink;

import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/5/19 17:25
 * FileName: Gatewayconfig
 * Description:
 */
@Configuration
@EnableWhiteListConfig
public class Gatewayconfig {



    @Bean
    GlobalFilter globalFilter(){
        return new GlobalAuthFilter();
    }


//    @Bean
//    WrapperResponseGlobalFilter responseGlobalFilter(){
//        return new WrapperResponseGlobalFilter();
//    }

    public static void main(String[] args) {
    String path="http://auth.51xuecheng.cn:9000/oauth2/consent/custom?scope=address%20phone%20openid%20profile%20custom%20email&client_id=hello&state=PCkVuNZlIvjah7xt34CQqjKctSUdQiM81LtVtinyDq8%3D";
        Matcher m = Pattern.compile("(?<schema>http|https)://(?<hostport>.*?)/(?<restpath>.*)").matcher(path);
        // 现在创建 matcher 对象
        System.out.println(m.groupCount());

        if (m.find( )) {
            System.out.println("Found value: " + m.group(0) );

            System.out.println("Found value: " + m.group(1) );System.out.println("Found value: " + m.group(2) );
            System.out.println(m.group(3));
        } else {
            System.out.println("NO MATCH");
        }
    }
}
